{% extends 'TopxiaWebBundle::bootstrap-modal-layout.html.twig' %}

{% set modal_class = 'modal-lg' %}

{% block title %}{% if liveLesson|default(null) %}编辑{% else %}新增{% endif %}直播课时{% endblock %}

{% block body %}
	
  <form class="form-horizontal" id="live-lesson-form"　method="post"  {% if parentId is defined%}data-parentId="{{parentId}}" {% endif %}
  
	  {% if liveLesson|default(null) %}
	  	action="{{ path('live_course_manage_lesson_edit',{courseId:liveCourse.id,lessonId:liveLesson.id}) }}" 
	  {% else %} 
	    action="{{ path('live_course_manage_lesson_create',{id:liveCourse.id}) }}"
	  {% endif %}
	  >
	 
    <div class="form-group">
      <label class="col-md-2 control-label" for="live-title-field">标题</label>
      <div class="col-md-8 controls">
        <input class="form-control" id="live-title-field" type="text" name="title" value="{{ liveLesson.title|default() }}" tabindex="2">
      </div>
    </div> 

  	<div class="form-group">
  		<label class="col-md-2 control-label" >直播开始时间</label>
  		<div class="col-md-8 controls" style="z-index:2000;">
        <input type="text"  name="startTime" class="form-control width-input width-input-large" value="{{ liveLesson.startTime|default()|date_format }}" tabindex="3">
        <div class="help-block" id="starttime-help-block">教师可在直播开始前1小时内进入直播教室，以准备相关教学资料。</div>
      </div>
  	</div>

  	<div class="form-group">
      <label class="col-md-2 control-label" >直播时长</label>
      <div class="col-md-8 controls">
        <input type="text"  name="timeLength" id="live-length-field" class="form-control width-input width-input-large" value="{{ liveLesson.length|default(4800000) }}" placeholder="时长" data-calculate-left-capacity-url="{{ path('live_lesson_calculate_left_capacity', {courseId:liveCourse.id, lessonId:liveLesson.id|default(0)}) }}" data-max-Student-Num = "{{ liveCourse.maxStudentNum }}" tabindex="4"> 分钟
        <div class="help-block" id="timelength-help-block"></div>
      </div>

      <input type="hidden" id="live_lesson_time_check" data-url="{% if liveLesson|default(null) %}{{path('live_lesson_time_check',{id:liveCourse.id,lessonId:liveLesson.id}) }}{% else %}{{path('live_lesson_time_check',{id:liveCourse.id})}}{% endif %}">
  	</div>
  	 <div class="form-group">
        <label class="col-md-2 control-label">课程类型</label>
          <div class="col-md-8 controls radios">
            {{ radios('type', {'om':'OM直播', 'qiniu':'七牛云直播'}, course.type|default('om') ) }}
        </div>
      </div>
	 <div class="form-group" style="display:none;" id="zbl">
      <label class="col-sm-2 control-label">直播流名称</label>
      <div class="col-sm-10">
        <div class="input-group">
          <input type="text" class="form-control" id="zblname" name="zhiboliu" required="required" >
          <span class="input-group-btn">
            <button type="button" class="btn btn-primary" onclick="get_zhiboliu()">获取直播流</button>
          </span>
        </div>
      </div>
    </div>
    <div class="form-group" id="zhiboliu" style="display: none;">
        <label class="col-sm-2 control-label" style="color: red;">选择流名称</label>
          <div class="col-sm-10 m-l-n">
                    <select class="form-control" id="souduo_zbl"multiple onchange="geturl()">
                    </select>
               </div>
    </div>
    <div class="form-group">
      <label class="col-md-2 control-label" >{{'直播地址'|trans}}</label>
      <div class="col-md-8 controls">
        <input type="text"  id="mediaUri" name="mediaUri" class="form-control" value="{{ liveLesson.mediaUri|default('http://') }}" placeholder="直播地址" >
        <div class="help-block" id="mediaUri-help-block"></div>
      </div>
    </div>

  	<div class="form-group">
  		<label class="col-md-2 control-label" for="live-summary-field">直播说明</label>
  		<div class="col-md-8 controls">
  			<textarea class="form-control" id="live_lesson-content-field" rows="10" name="summary"
          data-image-upload-url="{{ path('editor_upload', {token:upload_token('course')}) }}"
          data-flash-upload-url="{{ path('editor_upload', {token:upload_token('course', 'flash')}) }}" tabindex="5">
          {{ liveLesson.summary|default('') }}
        </textarea>
  		</div>
  	</div>

    <input type="hidden" name="_csrf_token" value="{{ csrf_token('site') }}">
  </form>

{% endblock %}

{% block footer %}
  <button type="button" class="btn btn-link" data-dismiss="modal">取消</button>
  <button type="submit" class="btn btn-primary"  data-toggle="form-submit" data-submiting-text="正在保存" data-target="#live-lesson-form" id="live-course-create-btn">保存</button>

  <script>app.load('live-course-manage/live-lesson-modal')</script>
<script type="text/javascript">
    
function sousuo(){
  var teacher=$("#teachers").val();
  $("#s-js").css('display',"block");
  var url="{{ path('admin_get_teacher') }}";
  $.post(url,{ teacher:teacher }, function(data){
     var list="";
    for (var i=0;i<data.length;i++)
    {
      list +="<option value='"+ data[i]['id'] +"'>"+data[i]['nickname']+"</option>";
    }
    document.getElementById('souduo').innerHTML = list;
   },'json');
}
 function gradeChange(){
    var objS = document.getElementById("souduo");
    var grade = objS.options[objS.selectedIndex].value;
    var grade1= objS.options[objS.selectedIndex].text;
    $("#teachers").val(grade1);
    $("#teacher").val(grade);
    $("#s-js").css('display',"none");
 }



 function get_zhiboliu(){
  var url="{{ path('admin_get_zhiboliu') }}";
  $.post(url, function(data){
     var list="";
    for (var i=0;i<data.length;i++)
    {
      list +="<option value='"+ data[i] +"'>"+data[i]+"</option>";
    }
    document.getElementById('souduo_zbl').innerHTML = list;
   },'json');
   $("#zhiboliu").css('display',"block");
 }
 function geturl(){
    var objS = document.getElementById("souduo_zbl");
        var name = objS.options[objS.selectedIndex].value;
        $("#zblname").val(name);
        var url="{{ path('admin_get_zhiboliu_url') }}";
        $.post(url,{name:name}, function(data){
        $("[name='mediaUri']").val(data);
     });
    $("#zhiboliu").css('display',"none"); 
    document.getElementById('submit').setAttribute("disabled","");
   }

	 $(function(){
		  $(":radio").click(function(){
		   	if($(this).val()=='qiniu'){
		   		$("#zbl").css('display','');
		   		document.getElementById("mediaUri").readOnly=true;
		   	}else{
		   	document.getElementById("mediaUri").readOnly=false;
		   		$("#zbl").css('display','none');
		   	}
		  });
	 });
</script>
   
   
   
</script>
{% endblock %}